home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.gsfc.nasa.gov!usenet
- From: Dirk Broer <Dirk.Broer@gsfc.nasa.gov>
- Newsgroups: comp.lang.c++
- Subject: Re: Help! Allocating 3 dimensional or greater arrays in C++
- Date: Sun, 28 Jan 1996 11:07:29 -0800
- Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
- Message-ID: <310BC971.D3B@gsfc.nasa.gov>
- References: <310CD09F.1D71@ns.vvm.com>
- NNTP-Posting-Host: control.gsfc.nasa.gov
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (Win16; I)
-
- Arun Nair wrote:
- >
- > I have been trying to allocate a 3 dimensional array in C++.
- >
- > void main()
- > {
- > int *matrix;
- > int **pmatrix = &matrix;
- > int ***ppmatrix = &pmatrix;
-
- why are you initializing pmatrix and ppmatrix?
-
- > int size;
- > matrix = new int[10];
- > pmatrix = new matrix[10];
- > ppmatrix = new pmatrix[10];
-
- To make an i x j x k matrix you must allocate i x j x k data points pluse j
- x k pointers. It is not necessary to allocate these linearly (ie in one
- block) unless you code specifically requires it.
-
- typedef int*** Matrix;
- typedef int** pMatrix;
- typedef int* ppMatrix;
-
- Matrix matrix;
- int a,b;
-
- matrix = new Matrix[i];
- for( a = 0; a < i; n++ )
- {
- matrix[n] = new pMatrix[j];
- for( b =0; b<j; b++ )
- matrix[a][b] = new ppMatrix[k];
- }
-